import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import * as path from 'path'
import dynamicImportVars from '@rollup/plugin-dynamic-import-vars';
// import eslintPlugin from 'vite-plugin-eslint'
function resolve(dir: string) {
  return path.join(__dirname, dir)
}
// https://vitejs.dev/config/
export default defineConfig({
  build:{
    // sourcemap: true
  },
  plugins: [vue(), dynamicImportVars({
    include: ['node_modules/codemirror/mode/*/*.js'],
    exclude: ['node_modules/codemirror/mode/vue/vue.js']
  })],
  server: {
    host: '0.0.0.0',
    port: 8888,
    proxy: {
      // '/api': {
      //   target: 'http://localhost:3333',
      //   changeOrigin: true,
      //   rewrite: (path) => path.replace(/^\/api/, ''),
      // },
    },
  },
  // {
  //     "@": resolve("src"),
  //     "views": resolve("src/views"),
  //     "api": resolve("src/api"),
  //     "store": resolve("src/store"),
  //     "components": resolve("src/components"),
  //
  // }
  resolve: {
    alias: [
      {
        find: /~(.+)/,
        replacement: resolve('node_modules/$1'),
      },
      {
        find: '@',
        replacement: resolve('src'),
      },
      {
        find: 'views',
        replacement: resolve('src/views'),
      },
      {
        find: 'api',
        replacement: resolve('src/api'),
      },
      {
        find: 'store',
        replacement: resolve('src/store'),
      },
      {
        find: 'components',
        replacement: resolve('src/components'),
      },
    ],
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: '@import "./src/styles/index.scss";', // 添加公共样式
      },
    },
  },
})
